<#include "/common.include"/>
/**
 * ${webNameCN}页面js
 * */
$.parser.onComplete=function(){
	/**
	 * ${webNameCN}datagrid列表
	 */
	${webName}_grid=$('#${webName}_grid').datagrid({
	    url:JS_CONTEXT+'/${classNameLowerCase}/get${className}PageList',
	    fit:true,
	    border:false,
	    toolbar: "#${webName}_grid_toolbar",
	    singleSelect : true,
	    fitColumns : true,
	    rownumbers:true,
		idField:'${pkColumnNameFirstLower}',
		nowrap:false,
		pagination:true, pageSize:20,pageList:[20, 30, 40, 50],
	    columns:[[
           {field:'aaxx',title:'选择',width:50,checkbox:true},
           {field:'axx',title:'序号',width:50,align:'center',
           	formatter:function(value, rowData, index){
           		var opts=$('#${webName}_grid').datagrid('options');
					if(opts.pageNumber==1){
						return index+1;
					}else{
						return opts.pageSize*(opts.pageNumber-1)+index+1;
					}
           	}
           }
           <#list table.columns as column>
               ,{field:'${column.columnNameLower}',title:'${column.remarks}',width:80,align:'center'}
           </#list>

           /*,
	        {field:'productName',title:'货品名称',width:80,align:'center'},
	        {field:'productCode',title:'牌号',width:100,align:'center'},
	        {field:'productStandard',title:'规格',width:80,align:'center'},
	        {field:'productArea',title:'产地',width:130,align:'center'},
	        {field:'productUnit',title:'单位',width:80,align:'center'},
	        {field:'productRemark',title:'备注',width:100,align:'center'},
	        {field:'createrTime',title:'创建日期',width:80,align:'center'}*/
	    ]]
	});
	
	
	
	//新增按钮
	$("#add_${webName}_btn").click(function(){
		$("#save_${webName}_dialog").form("clear");
		$('#save_${webName}_dialog').form('enable');
		$("#${webName}_btns").show();
		$("#save_${webName}_dialog").dialog({title:'新增${webNameCN}'}).dialog("open");
		
	});
	
	//修改按钮
	$("#edit_${webName}_btn").click(function(){
		var rows=${webName}_grid.datagrid("getChecked");
		if(rows.length>0){
			$('#save_${webName}_dialog').form('enable');
			$("#${webName}_btns").show();
			$('#save_${webName}_form').form('load',rows[0]);
			$('#save_${webName}_dialog').dialog({title: '修改${webNameCN}'}).dialog("resize").dialog("open").dialog("center");
		}else{
			$.messager.alert("提示", "请选择要修改的${webNameCN}!", "info");
		}
	});
	
	
	//delete真删除
	//remove假删除
	//删除按钮
	$("#delete_${webName}_btn").click(function(){
		var rows=${webName}_grid.datagrid("getChecked");
		if(rows.length>0){
			$.messager.confirm("询问", "确定要删除该${webNameCN}吗?", function(r){
				if(r){
					$.ajax({
						type : "POST",
						url : JS_CONTEXT+"/${classNameLowerCase}/delete${className}", 
			            data : {
			            	/*productId:rows[0].productId*/
			            }, 
			            dataType : "json", 
			            cache : false,
			            async: false,
			            success : function(data) {
			            	if(data.success){
			            		reload_${webName}_grid();
			            		$.messager.show({title:"提示",msg:data.message});
			            	}else{
			            		$.messager.alert("提示", data.message, "error");
			            	}
			            } 
			       });
				}
			});
		}else{
			$.messager.alert("提示", "请选择要删除的${webNameCN}!", "info");
		}
	});
	
	//查看按钮
	$("#view_${webName}_btn").click(function(){
		var rows=${webName}_grid.datagrid("getChecked");
		if(rows.length>0){
			$('#save_${webName}_dialog').form('load',rows[0]);
			$('#save_${webName}_dialog').form('disable');
			$("#${webName}_btns").hide();
			$('#save_${webName}_dialog').dialog({title: '查看${webNameCN}'}).dialog("resize").dialog("open").dialog("center");
		}else{
			$.messager.alert("提示", "请选择要查看的${webNameCN}!", "info");
		}
	});
	
	//保存按钮
	$("#${webName}_save_btn").unbind("click");
	$("#${webName}_save_btn").click(function(){
		$("#save_${webName}_form").form("submit", {
			url:JS_CONTEXT+"/${classNameLowerCase}/save${className}",
			onSubmit:function(param){
				var flag=$(this).form("validate");
				if(flag){
					$.messager.progress(5000);
				}
				return flag;
			},
			success:function(data){
				$.messager.progress('close');
				data=eval("("+data+")");
				if(data.success){
					$("#save_${webName}_dialog").dialog("close");
					$.messager.show({title:"提示",msg:data.message});
					reload_${webName}_grid();
				}else{
					$.messager.alert("提示", data.message, "error");
				}
			}
		});
	});
	
	//取消按钮
	$("#${webName}_cancel_btn").unbind("click");
	$("#${webName}_cancel_btn").click(function(){
		$('#save_${webName}_dialog').dialog("close");
	});
	
	
	//查询按钮
	$("#query_${webName}_btn").click(function(){
		reload_${webName}_grid();
	});
	
	//重置按钮
	$("#resset_${webName}_btn").click(function(){
		reset_${webName}_grid();
	});
	
};


/**
 * 查询${webNameCN}
 */
function reload_${webName}_grid(){
	var param=$("#${webName}_search_form").getFormParams();
	${webName}_grid.datagrid("load", param);
	${webName}_grid.datagrid("clearChecked");
}

/**
 * 重置${webNameCN}
 */
function reset_${webName}_grid(){
	var param=$("#${webName}_search_form").form("clear");
	var param=$("#${webName}_search_form").getFormParams();
	${webName}_grid.datagrid("load", param);
	${webName}_grid.datagrid("clearChecked");
}


